package com.leyou.user.config;

import com.leyou.common.auth.utils.RsaUtils;
import com.leyou.common.enums.ExceptionEnum;
import com.leyou.common.exceptions.LyException;
import lombok.Data;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.security.PublicKey;

@ConfigurationProperties(prefix = "ly.jwt")
@Data
public class JwtProperties implements InitializingBean {

    private String pubKeyPath;
    private PublicKey publicKey;

    private AppTokenInfo app=new AppTokenInfo();

    @Override
    public void afterPropertiesSet() throws Exception {
        try {
            this.publicKey=RsaUtils.getPublicKey(pubKeyPath);
        } catch (Exception e) {
            throw new LyException(ExceptionEnum.GET_KEY_ERROR);
        }
    }

    @Data
    public class AppTokenInfo{
        private Long id;
        private String secret;
        private String headerName;
    }


}
